#include "EleFactory.h"
#include "HtmlElement.h"
#include <QMetaType>
#define METAOBJCET5
EleFactory::EleFactory(QObject *prent):QObject(prent){
#ifdef METAOBJCET
    qDebug()<<  qRegisterMetaType<class Div>();
    qDebug()<<  qRegisterMetaType<class Table>();
    qDebug()<<  qRegisterMetaType<class Tr>();
    qDebug()<<  qRegisterMetaType<class Td>();
    qDebug()<<  qRegisterMetaType<class P>();
    qDebug()<<  qRegisterMetaType<class Img>();
    qDebug()<<  qRegisterMetaType<class Title>();

    qDebug()<<  qRegisterMetaType<class H1>();
    qDebug()<<  qRegisterMetaType<class H2>();
    qDebug()<<  qRegisterMetaType<class H3>();
    qDebug()<<  qRegisterMetaType<class H4>();
    qDebug()<<  qRegisterMetaType<class Hr>();
    qDebug()<<  qRegisterMetaType<class Span>();
#endif
}

HtmlElement *EleFactory::eleTypeFactory(EleType type)
{
    HtmlElement *ele = nullptr;

#ifdef METAOBJCET
    void * e = QMetaType::create(type);
    qDebug()<<e<<type;
    if(e)
    {
        ele = (HtmlElement*)e;
    }
#else
    switch (type) {
    case Div:
        ele = new class  Div(this);
        break;
    case Table:
        ele = new class Table(this);
        break;
    case Tr:
        ele = new class Tr(this);
        break;
    case Td:
        ele = new class Td(this);
        break;
    case P:
        ele = new class P(this);
        break;
    case Img:
    {
        HtmlElement * p = new class   P(this);
        p->forMate();
        HtmlElement * span = new class  Span(this);
        span->forMate();

        p->appendElement(span);

        ele = new class Img(this);
        ele->appendElement(span);
        ele->setOutObj(p);


    }
        break;
    case Span:
        ele = new class Span(this);
        break;
    case Hr:
        ele = new class Hr(this);
        break;
    case H1:
        ele = new class H1(this);
        break;
    case H2:
        ele = new class H2(this);
        break;
    case H3:
        ele = new class H3(this);
        break;
    case H4:
        ele = new class H4(this);
        break;
    default:
        break;
    }
#endif
    ele->forMate();
    return ele;

}

HtmlElement *EleFactory::eleTypeFactory(class QString eleName)
{
    int id = QMetaType::type(eleName.toStdString().c_str());

    return  eleTypeFactory((EleType)id);
}
